package com.heima.minio.test;

import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;

import java.io.FileInputStream;

public class Demo {
    public static void main(String[] args) throws Exception {
        // 0. 准备文件数据
        FileInputStream is =  new FileInputStream("D:\\list.html");;

        // 1. 初始化minio的客户端
        MinioClient minioClient = MinioClient.builder()
                .endpoint("http://192.168.200.130:9000")  // 路径
                .credentials("minio", "minio123")
                .build();

        // 2. 调用客户端的方法上传文件到minio的桶中
        PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                .bucket("leadnews")
                .object("list.html")
                .contentType("text/html")
                .stream(is, is.available(), -1)
                .build();
        ObjectWriteResponse response = minioClient.putObject(putObjectArgs);

        System.out.println(response.headers());
        System.out.println("上传成功：路径为：http://192.168.200.130:9000/leadnews/list.html");

    }
}
